a = int(input())
if a >= 10000 or a <= 999:
    print('0')
    exit()
c = a // 1000
c1 = a // 100 % 10
c2 = a // 10 % 10
c3 = a % 10
b = [c, c1, c2, c3, c * 10 + c1, c * 100 + c1 * 10 + c2,a, c1 * 10 + c2,c1 * 100 + c2 * 10 + c3,c2*10+c3]
MAX = 0
for i in range(len(b)):
    z = 0
    for j in range(2, b[i]//2+1):
        if b[i] % j == 0:
            z += 1
        if z <= 0:
            if MAX < b[i]:
                if b[i] != 1:
                    MAX = b[i]
print(MAX)
